package space.xxhui

import org.apache.kafka.clients.producer.{KafkaProducer, ProducerRecord}

import java.util.Properties
import scala.io.StdIn._
import scala.util.control.Breaks

/**
 * @author HitvzByHui
 *         date 2021-09-05
 */
object Main extends App {

  var brokers = "175.27.191.203:9092,175.27.191.203:9093"
  var topic = "wordFreq"
  val props = new Properties()
  props.put("bootstrap.servers",brokers)
  props.put("client.id","kafkaDataProducer")
  props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer")
  props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer")

  var producer = new KafkaProducer[String,String](props)

  var loop = new Breaks
  loop.breakable {
    while (true) {
      val line = readLine(">");
      println(line)
      val data = new ProducerRecord[String,String](topic,line,line)
      producer.send(data)
      if (line.equals("bye")) {
        loop.break
      }
    }
  }
  producer.close()

}
